package controller;

import moder.Pager;
import moder.TbProduct;
import service.AdminProductService;
import service.TbCategoryService;
import service.impl.AdminProductServiceImpl;
import service.impl.TbCategoryImpl;

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/adminproduct.do")
public class AdminProductPagerController extends HttpServlet {

    public AdminProductPagerController() {
        super();
    }

    AdminProductService service = new AdminProductServiceImpl();
    TbCategoryService category = new TbCategoryImpl();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //拿到请求数据
        String pindex = request.getParameter("pageindex");
        if(pindex==null){ //第1页;
            pindex ="1";
        }
        Integer pageindex = Integer.parseInt(pindex);
        Integer pagesize = 5;
        Pager<TbProduct> pageinfo =service.goodsPager(pagesize, pageindex, "8");
        request.getSession().setAttribute("pageinfo",pageinfo);

        service.TbProductService service = new service.impl.TbProductServiceImpl();
        List<TbProduct> product = service.findAllProduct();
        request.getSession().setAttribute("allproduct", product);

        System.out.println(pageinfo.getPagecount());
        response.sendRedirect("/admin/inventory.jsp");
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}

